 package com.example.activitytest

import android.content.Intent
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.widget.Toast
import kotlinx.android.synthetic.main.first_layout.*

 class FirstActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.first_layout)

        //创建按钮点击事件
        button1.setOnClickListener{

//            添加Toast
//            Toast.makeText(this,"You clicked Button 1",Toast.LENGTH_SHORT).show()

//            销毁activity
//            Toast.makeText(this,"Activity被销毁",Toast.LENGTH_SHORT).show()
//            finish()

//            添加显式Intent
//            val intent = Intent(this,SecondActivity::class.java)
//            startActivity(intent)

//            添加隐式Intent
//            val intent = Intent("com.example.activitytest.ACTION_START")
//            intent.addCategory("com.example.activitytest.MY_CATEGORY")
//            startActivity(intent)

//            打开网页
//            val intent = Intent(Intent.ACTION_VIEW)
//            intent.data = Uri.parse("https://www.baidu.com")
//            startActivity(intent)

//            打开拨号界面
//            val intent = Intent(Intent.ACTION_DIAL)
//            intent.data = Uri.parse("tel:10086")
//            startActivity(intent)

//            向下一个Activity传递数据
            val data = "Hello SecondActivity"
            val intent = Intent(this,SecondActivity::class.java)
            intent.putExtra("extra_data",data)
            startActivity(intent)
        }
    }

     //创建Menu
     override fun onCreateOptionsMenu(menu: Menu?): Boolean {
         menuInflater.inflate(R.menu.main,menu)
         return true
//         return super.onCreateOptionsMenu(menu)
     }

//     创建菜单响应方法
     override fun onOptionsItemSelected(item: MenuItem): Boolean {
         when(item.itemId){
             R.id.add_item -> Toast.makeText(this,"You clicked Add",Toast.LENGTH_SHORT).show()
             R.id.remove_item -> Toast.makeText(this,"You clicked Remove",Toast.LENGTH_SHORT).show()
         }
    return true
//         return super.onOptionsItemSelected(item)
     }
 }